﻿import QtQuick 2.6
import QtQuick.Window 2.2

Window {
    id: winRoot;
    property bool isFull: false;
    property int margin: 2;
    property int quitNum: 0;
    visible: true
    width: Screen.width * (isFull ? 1 : 0.3) + margin*2 ;
    height: Screen.height * (isFull ? 1 : 0.3) + margin*2;
    //flags: Qt.MSWindowsFixedSizeDialogHint | Qt.FramelessWindowHint
    color: "transparent"
    x: (isFull ? -margin : (Screen.width-width)/2);
    y: (isFull ? -margin : (Screen.height-height)/2);
    
    function reqQuit(){
        quitNum += 1;
        
        var timer = Qt.createQmlObject('import QtQuick 2.0; Timer{interval: 1000;}',winRoot,"timer");
        timer.triggered.connect(function(){
            quitNum = 0;
        });
        timer.start();
        
        //1秒内连续请求2次，就退出
        if( quitNum >= 2 )
            close();
    }
    
    Rectangle{
        anchors.fill: parent;
        anchors.margins: margin;
        color: "#f5f5f5";
    }
    
    //主要用于鼠标滑出当前显示范围后，当前显示范围跟着动
    MouseArea{
        id: fullMa;
        anchors.fill: parent;
        hoverEnabled: true;
        onMouseXChanged: Qt.callLater(loader.checkPosForMouse);
        onMouseYChanged: Qt.callLater(loader.checkPosForMouse);
        onPressed: mouse.accepted = false;
    }
    
    Loader{
        id: loader;
        anchors.fill: parent;
        anchors.margins: margin;
        Component.onCompleted: Qt.callLater(init);
        clip: true;
        focus: true;
        
        onLoaded: {
            item.reqQuit.connect(reqQuit);
        }
        
        function init(){
            setSource("qrc:/MGameMainCore.qml",{"fullMa": fullMa,"scrMargin": margin});
        }
        
        function checkPosForMouse(){
//            if( item )
//                item.mouseChange();
        }
    }
    
}




